home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 2.toast / pc / sample code / overview / dtscpluslibrary / sources / colorpicker.cp < prev    next >
Encoding:
Text File  |  2000-09-28  |  3.1 KB  |  121 lines

  1. /*
  2.     File:        ColorPicker.cp
  3.  
  4.     Contains:    TColorPicker is a simple color picker utility class    
  5.                   TColorPicker.cp contains the TColorPicker member function definitions. 
  6.  
  7.     Written by: Kent Sandvik    
  8.  
  9.     Copyright:    Copyright © 1993-1999 by Apple Computer, Inc., All Rights Reserved.
  10.  
  11.                 You may incorporate this Apple sample source code into your program(s) without
  12.                 restriction. This Apple sample source code has been provided "AS IS" and the
  13.                 responsibility for its operation is yours. You are not permitted to redistribute
  14.                 this Apple sample source code as "Apple sample source code" after having made
  15.                 changes. If you're going to re-distribute the source, we require that you make
  16.                 it clear in the source that the code was descended from Apple sample source
  17.                 code, but that you've made changes.
  18.  
  19.     Change History (most recent first):
  20.                 8/18/1999    Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
  21.                 
  22.  
  23. */
  24. #ifndef _COLORPICKER_
  25. #include "ColorPicker.h"
  26. #endif
  27.  
  28. // CONSTRUCTORS AND DESTRUCTORS
  29. #pragma segment Color
  30. TColorPicker::TColorPicker(Boolean keepTrack)
  31. {
  32.     fKeepTrack = keepTrack;
  33.  
  34.     // define the starting color scheme as white (arbitrary selection)
  35.     fInitialColor.red = fInitialColor.green = fInitialColor.blue = 0xFFFF;
  36.  
  37.     // Define the dialog point for the color picker, default setting.
  38.     // Note that -1,-1 indicates that the color picker will be placed on what
  39.     // the picker considers to be the best screen, optimizing depth and color.
  40.     // In addition, it centers the dialog box nicely. If you want to change this, change
  41.     // the lines, but I wouldn't :-).
  42.     fDialogPoint.v = -1;
  43.     fDialogPoint.h = -1;
  44. }
  45.  
  46.  
  47. #pragma segment Color
  48. TColorPicker::~TColorPicker()
  49. // Default constructor -- empty for the time being.
  50. {
  51. }
  52.  
  53.  
  54. // MAIN INTERFACE
  55. #pragma segment Color
  56. Boolean TColorPicker::Select(Str255 string)
  57. // Select a color from the picker.
  58. {
  59.     Boolean result = ::GetColor(fDialogPoint, string, &fInitialColor, &fSelectedColor);
  60.     if (fKeepTrack && result)                    // we want to keep track of selected color?
  61.         fInitialColor = fSelectedColor;            // then save it for later use
  62.     return result;
  63. }
  64.  
  65.  
  66. #pragma segment Color
  67. void TColorPicker::Reset()
  68. // Reset any initial color setting to 'white'.
  69. {
  70.     fInitialColor.red = fInitialColor.green = fInitialColor.blue = 0xFFFF;
  71. }
  72.  
  73.  
  74. #pragma segment Color
  75. RGBColor TColorPicker::GetSelectedColor() const
  76. // Return the selected color.
  77. {
  78.     return fSelectedColor;
  79. }
  80.  
  81.  
  82. #pragma segment Color
  83. CMYColor TColorPicker::GetSelectedCMYColor()
  84. // Return the selected color in CMY values.
  85. {
  86.     CMYColor temp;
  87.     ::RGB2CMY(&fSelectedColor, &temp);
  88.  
  89.     return temp;
  90. }
  91.  
  92.  
  93. #pragma segment Color
  94. HSLColor TColorPicker::GetSelectedHSLColor()
  95. // Return the selected color in HSL values.
  96. {
  97.     HSLColor temp;
  98.     ::RGB2HSL(&fSelectedColor, &temp);
  99.  
  100.     return temp;
  101. }
  102.  
  103.  
  104. #pragma segment Color
  105. HSVColor TColorPicker::GetSelectedHSVColor()
  106. // Return the selected color in HSV values.
  107. {
  108.     HSVColor temp;
  109.     ::RGB2HSV(&fSelectedColor, &temp);
  110.  
  111.     return temp;
  112. }
  113.  
  114. // _________________________________________________________________________________________________________ //
  115.  
  116. /*    Change History (most recent last):
  117.   No        Init.    Date        Comment
  118.   1            khs        1/3/93        New file
  119.   2            khs        1/5/93        Cleanup
  120. */
  121.